<div class="layui-card-body ">
    <form id="update" style="margin-top: 15px;" class="layui-form" action="{{route('admin.basic.update')}}">
        @csrf
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{{$data['id']}}">
                <input type="text" name="basic" autocomplete="off" value="{{$data['basic']}}"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">科目分类</label>
            <div class="layui-input-block">
                <div id="category_id"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">组织机构</label>
            <div class="layui-input-block">
                <input type="hidden" name="org_code" id="org_code" value="{{$data['org_code']}}" />
                <div id="org_id"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">缩略图</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="thumb">上传图片</button>
                    <div class="layui-upload-list">
                        @if(empty($data['thumb']))
                        <img class="layui-upload-img" id="pic" width="100" height="100">
                        @else
                        <img class="layui-upload-img" id="pic" width="100" height="100" src="/{{$data['thumb']}}">
                        @endif
                        <p id="demoText"></p>
                        <input type="hidden" name="thumb" value="{{$data['thumb']}}">
                    </div>
                    <div style="width: 95px;">
                        <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="progress">
                            <div class="layui-progress-bar" lay-percent=""></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">考场价格</label>
            <div class="layui-input-block">
                <input type="text" name="price" autocomplete="off" value="{{$data['price']/100}}"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开启状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="关闭" @if($data['status'] == 0)checked=""@endif>
                <input type="radio" name="status" value="1" title="开启" @if($data['status'] == 1)checked=""@endif>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">加入方式</label>
            <div class="layui-input-block">
                <select id="type" name="join_type">
                    {!! Code::getOptionsByCode('BASIC_JOIN_TYPE',$data['join_type']) !!}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">查阅试卷</label>
            <div class="layui-input-inline">
                <input type="radio" name="viewenable" value="0" title="否" @if($data['viewenable'] == 0)checked=""@endif>
                <input type="radio" name="viewenable" value="1" title="是" @if($data['viewenable'] == 1)checked=""@endif>
            </div>
            <div class="layui-form-mid layui-word-aux">正式考试考生是否可以查阅试卷</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="description" class="layui-textarea" rows="3">{{$data['description']}}</textarea>
            </div>
        </div>
    </form>
</div>
<script src="{{asset('layui/modules/xm-select.js')}}"></script>
<script src="{{asset('js/tree/select.js')}}"></script>
<script>
    var idx = -1;
    layui.use(['xmSelect','upload','element'], function () {
        var xmSelect = layui.xmSelect,upload = layui.upload,element = layui.element;
        let params=selectTreeParams('#category_id','category_id','请选择',{{$data['category_id']}}, {!! $category !!},function (data){});
        xmSelect.render(params)
        let org=selectTreeParams('#org_id','org_id','请选择',{{$data['org_id']}}, {!! $org !!},function (data){
            $("input[name='org_code']").val(data['arr'][0]['code'])
        });
        xmSelect.render(org)
        var uploadInst = upload.render({
            elem: '#thumb'
            ,url: '{{route('admin.set.create.attach')}}'
            ,field: "img"
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#pic').attr('src', result); //图片链接（base64）
                });
                element.progress('progress', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            ,data: {"_token": "{{csrf_token()}}","path": "basic"}
            ,done: function(res){
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                $('#demoText').html('');//置空上传失败的状态
                $('input[name="thumb"]').val(res.path);
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('progress', n + '%');
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });

    });
</script>
